//
//  main.swift
//  Swift01
//
//  Created by lishunchi on 2017/9/12.
//  Copyright © 2017年 lishunchi. All rights reserved.
//

import Foundation

print("15180600602,李顺驰")

struct Student{
    var name:String
    var mathScore:Int
    var englishScore:Int
    var average:Float
    
    init(name:String,mathScore:Int,englishScore:Int) {
        self.name = name
        self.mathScore = mathScore
        self.englishScore = englishScore
        self.average = Float(self.mathScore + self.englishScore) / 2
    }
}

func sortWithAverage(students:[Student]) -> [Student]{
    var result = students;
    
    for i in 0...9{
        for j in i...9{
            if result[i].average < result[j].average{
                let temp = result[i]
                result[i] = result[j]
                result[j] = temp
            }
        }
    }
    return result
}
var student01 = Student(name: "NUM01", mathScore: 67, englishScore: 98)
var student02 = Student(name: "NUM02", mathScore: 73, englishScore: 37)
var student03 = Student(name: "NUM03", mathScore: 26, englishScore: 84)
var student04 = Student(name: "NUM04", mathScore: 36, englishScore: 96)
var student05 = Student(name: "NUM05", mathScore: 25, englishScore: 96)
var student06 = Student(name: "NUM06", mathScore: 36, englishScore: 96)
var student07 = Student(name: "NUM07", mathScore: 36, englishScore: 74)
var student08 = Student(name: "NUM08", mathScore: 74, englishScore: 47)
var student09 = Student(name: "NUM09", mathScore: 37, englishScore: 73)
var student10 = Student(name: "NUM10", mathScore: 73, englishScore: 83)

var result = sortWithAverage(students: [student01,
                                        student02,
                                        student03,
                                        student04,
                                        student05,
                                        student06,
                                        student07,
                                        student08,
                                        student09,
                                        student10])

print("英语和数学平均分的成绩从小到大排列为:")

for i in 0..<result.count{
    print("姓名:\(result[i].name),数学成绩:\(result[i].mathScore),英语成绩:\(result[i].englishScore),平均分:\(result[i].average)")
}
